The complete method is seen below.
public int Fib( int N ) { if ( N==1 ) return 1; else if ( N==2 ) return 1; else return Fib( N-1 ) + Fib( N-2 ); }
It may worry you that the code for Fib(int N)
uses
Fib(N-1)
and Fib(N-2)
.
This is fine.
Look at the math-like definition. Play with it until you understand it.
The program says the same thing but uses a different language (Java) to say it.
It is the job of the Java system to make sure that you get the computation that you ask for.